import { Entry } from "@/types/intro";
import { User } from "@/types/user";

/**
 * 生成随机HTML内容
 * @param paragraphs 段落数量
 */
function generateRandomHtml(paragraphs = 3): string {
    const tags = ["p", "h2", "h3", "ul", "ol"];
    const lorem =
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
    let html = "";

    for (let i = 0; i < paragraphs; i++) {
        const tag = tags[Math.floor(Math.random() * tags.length)];

        if (tag === "ul" || tag === "ol") {
            // 列表标签
            const listItems = Math.floor(Math.random() * 5) + 2;
            let listContent = "";
            for (let j = 0; j < listItems; j++) {
                listContent += `<li>列表项 ${j + 1}: ${lorem.substring(
                    0,
                    Math.floor(Math.random() * 30) + 10
                )}</li>`;
            }
            html += `<${tag}>${listContent}</${tag}>`;
        } else if (tag === "h2" || tag === "h3") {
            // 标题标签
            html += `<${tag}>标题 ${i + 1}: ${lorem.substring(
                0,
                Math.floor(Math.random() * 20) + 5
            )}</${tag}>`;
        } else {
            // 段落标签
            html += `<${tag}>${lorem.substring(
                0,
                Math.floor(Math.random() * 100) + 50
            )}</${tag}>`;
        }
    }

    return html;
}

/**
 * 生成随机Entry数组
 * @param n 生成数量
 */
export function generateRandomEntries(n: number): Entry[] {
    return Array.from({ length: n }, (_, i) => ({
        id: `entry-${i + 1}`,
        name: `项目 ${i + 1}`,
        rank: Math.floor(Math.random() * 100),
        content: generateRandomHtml(Math.floor(Math.random() * 5) + 1),
        createTime:
            Date.now() - Math.floor(Math.random() * 3600 * 24 * 30 * 1000), // 最近30天内的随机时间
    }));
}
